﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!-- 权限验证 -->
    <script type="text/javascript" src="static/WebApi.js"></script>
    <title>资产登记</title>
</head>
<body>
    <div class="page-container">
        <form class="form form-horizontal" id="form-Personal-add">
            <h2 style="text-align:center">资产登记</h2>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>借款人员基本信息：</label>
                <div class="formControls col-xs-8 col-sm-9" id="add">
                    <div class="addBorrower" id="borrower0">
                        <div class="row cl">
                            <label class="form-label col-xs-3 col-sm-2"><span class="c-red "></span>借款人员姓名：</label>
                            <div class="formControls col-xs-3 col-sm-3">
                                <input type="text" class="input-text T_Name" value="" placeholder="请输入借款人员姓名" id="T_Name0" name="T_Name0" maxlength="10" required="required">
                            </div>
                            <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>身份证号：</label>
                            <div class="formControls col-xs-3 col-sm-4">
                                <input type="text" class="input-text T_Idcard" value="" placeholder="请输入身份证号" id="T_Idcard0" name="T_Idcard0" maxlength="18" required="required">
                            </div>
                        </div>
                        <div class="row cl">
                            <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>联系电话：</label>
                            <div class="formControls col-xs-3 col-sm-3">
                                <input type="text" class="input-text T_PhoneAll" value="" placeholder="请输入联系电话" id="T_Phone0" name="T_PhoneAll0" maxlength="11" required="required">
                            </div>
                            <div class="formControls col-xs-6 col-sm-6">
                                <input type="button" class="btn btn-success" onclick="addborrower()" value="添加借款人" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4  col-sm-2"><span class="c-red"></span>联系人：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="T_Linkman" name="T_Linkman" maxlength="10" required="required" />
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>联系电话：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="T_Phone" name="T_Phone" maxlength="11" required="required" />

                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>房屋剩余年限：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="T_Loanyear" name="T_Loanyear" maxlength="3" />

                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>贷款额度(万元）：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="T_Loanlimit" name="T_Loanlimit" maxlength="10" required="required" />

                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">实际交易价(万元）：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="T_Actual" name="T_Actual" maxlength="10" required="required" />
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">房屋坐落：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="T_Located" name="T_Located" maxlength="100" required="required" />
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">房屋用途：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box">
                        <select class="select" id="T_PurposeID" name="T_PurposeID"></select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">建成年代：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" id="T_Activate" name="T_Activate" maxlength="4" />
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">报告类型：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box">
                        <select class="select" id="T_ReportID" name="T_ReportID"></select>
                    </span>
                </div>

            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">评估受理：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <span class="check-box">
                        <input id="T_Assess1" name="T_Assess" type="checkbox" value="审核评估登记表" /><label for="P_assess">审核评估登记表</label>
                    </span>
                    <span class="check-box">
                        <input id="T_Assess2" name="T_Assess" type="checkbox" value="身份证明" /><label for="P_assess1">身份证明</label>
                    </span>
                    <span class="check-box">
                        <input id="T_Assess3" name="T_Assess" type="checkbox" value="房屋权属" /><label for="P_assess2">房屋权属</label>
                    </span>
                    <span class="check-box">
                        <input id="T_Assess4" name="T_Assess" type="checkbox" value="网签合同" /><label for="P_assess3">网签合同</label>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">现场勘察分配：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <span class="select-box">
                        <select name="T_DepartmentID" class="select" id="T_DepartmentID" required="required">
                            <option value="0">延庆部</option>
                            <option value="1">昌平部</option>
                            <option value="1">海淀部</option>
                        </select>
                    </span>
                </div>
                <div class="formControls col-xs-4 col-sm-5">
                    <span class="select-box">
                        <select name="T_SiteSurveyid" class="select" id="T_SiteSurveyid" required="required">
                            <option value="0">张三</option>
                            <option value="1">李四</option>
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-4 col-sm-5  col-xs-offset-5 col-sm-offset-5">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;登记&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </div>
    <!--基本js脚本-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--扩展js脚本-->
    <script type="text/javascript" src="static/Common.js"></script>
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">
        var uri = document.location.search;//接收页面传值
        var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
        var T_ReportNumber = uri.substr(i);//截取问号前面的值
        $(function () {
            $("option").remove();
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });
            //等级页面字典下拉框查询
            $.ajax({
                type: "get",
                url: ApiUrl + "api/Dictionary/GetDictionaryList",
                data: {
                    Dmenuid: [1, 40]
                },
                success: function (data, status) {
                    if (status == "success") {
                        $("#T_PurposeID").empty();
                        $("#T_ReportID").empty();
                        $(data).each(function (i, obj) {
                            $(obj).each(function (j, item) {
                                switch (item.Dmenuid) {
                                    case 1:
                                        $("#T_PurposeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                        break;
                                    case 40:
                                        $("#T_ReportID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                                        break;
                                    default:
                                        break;
                                }
                            })
                        })
                    }
                }
            });
            var P_DepartmentID = "";
            //添加用户信息页面-部门下拉框
            $.ajax({
                type: "get",
                url: ApiUrl + "api/Department/GetHouseType",
                async: false,
                success: function (data, status) {
                    if (status == "success") {
                        $(data).each(function (i, item) {
                            $("#T_DepartmentID").append("<option value=" + item.T_DepartmentID + ">" + item.T_Dname + "</option>");
                            P_DepartmentID = $("#T_DepartmentID").val();

                        })
                    }
                }
            });
            //添加用户信息页面-员工下拉框
            Selectuser(P_DepartmentID);

            //部门发生变化时改变员工的下拉框
            $("#T_DepartmentID").change(function () {
                var s1 = $(this).val();

                //添加用户信息页面-员工下拉框
                Selectuser(s1);
            })

            //保存登记
            $("#form-Personal-add").validate({
                rules: {
                    T_Phone: {
                        required: true,
                    }
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function () {
                    insertPersonal();
                }
            });

        });
        function Selectuser(id) {
            //添加用户信息页面-员工下拉框
            $.ajax({
                type: "get",
                url: ApiUrl + "api/Staff/GetHouseType",
                data: {
                    deptid: id
                },
                success: function (data, status) {
                    if (status == "success") {
                        $("#T_SiteSurveyid").empty();
                        $(data).each(function (i, item) {
                            $("#T_SiteSurveyid").append("<option value=" + item.T_StaffID + ">" + item.T_Name + "</option>")
                        })
                    }
                }
            });
        }

        //借款人动态添加
        window.a = 0;
        function addborrower() {
            a++;
            var html = '<div class="addBorrower" id=borrower' + a + '>'
                    + '<div class="row cl">'
                    + '    <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>借款人员姓名：</label>'
                    + '    <div class="formControls col-xs-3 col-sm-3">'
                    + '        <input type="text" class="input-text T_Name"  placeholder="请输入借款人员姓名" maxlength="10" id="T_Name' + a + '" name="T_Name' + a + '" required="required"/>'
                    + '    </div>'
                    + '    <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>身份证号：</label>'
                    + '    <div class="formControls col-xs-3 col-sm-4">'
                    + '        <input type="text" class="input-text T_Idcard"  placeholder="请输入身份证号" maxlength="18" id="T_Idcard' + a + '"  name="T_Idcard' + a + '" required="required"/>'
                    + '    </div>'
                    + '</div>'
                    + '<div class="row cl">'
                    + '    <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>联系电话：</label>'
                    + '    <div class="formControls col-xs-3 col-sm-3">'
                    + '        <input type="text" class="input-text T_PhoneAll"  placeholder="请输入联系电话" maxlength="11" id="T_PhoneAll' + a + '"  name="T_PhoneAll' + a + '" required="required"/>'
                    + '    </div>'
                    + '    <div class="formControls col-xs-6 col-sm-6">'
                    + '        <input class="btn btn-danger radius" onclick="removeborrower(' + a + ')" value="删除借款人" type="button"/>'
                    + '    </div>'
                    + '</div></div>';
            $("#add").append(html);
        }
        function removeborrower(a) {
            $('#borrower' + a + '').remove();
        }

        //资产登记的数据添加
        function insertPersonal() {
            layer.msg('添加中....', {
                icon: 16, shade: 0.01
            });

            //评估受理多选框
            var T_Assess = [];
            $(".check-box input[name='T_Assess']").each(function () {
                if (this.checked)
                    T_Assess.push(this.value);
            })
            if (T_ReportNumber != "" && T_ReportNumber != null) {
                var Collateral_Personal = {
                    T_ReportNumber: T_ReportNumber,
                    T_Linkman: $("#T_Linkman").val(),                              //看房联系人
                    T_Phone: $("#T_Phone").val(),                                //看房联系人电话
                    T_Loanyear: $("#T_Loanyear").val() + "",                                //房屋使用年限
                    T_Loanlimit: $("#T_Loanlimit").val(),                                //贷款额度
                    T_Actual: $("#T_Actual").val(),                                       //实际交易价
                    T_Located: $("#T_Located").val(),                                     //房屋坐落
                    T_PurposeID: $("#T_PurposeID option:checked").attr("value"),            //房屋用途编号
                    T_Activate: $("#T_Activate").val() + "",                                   //建成年代
                    T_ReportID: $("#T_ReportID option:checked").attr("value"),              //报告类型编号
                    T_Assess: T_Assess.toString(),                                                 //评估受理
                    T_DepartmentID: $("#T_DepartmentID option:checked").attr("value"),         //抵押物管理点（现场勘查所属部门id）
                    T_SiteSurveyid: $("#T_SiteSurveyid option:checked").attr("value"),         //抵押物管理点（现场勘查所属部门下的某员工）
                    T_Iid: LoginUserID,                                            //登记员(房产登记者),员工表中的外键
                }
            }
            else {
                var Collateral_Personal = {
                    T_Linkman: $("#T_Linkman").val(),                              //看房联系人
                    T_Phone: $("#T_Phone").val(),                                //看房联系人电话
                    T_Loanyear: $("#T_Loanyear").val(),                                //房屋使用年限
                    T_Loanlimit: $("#T_Loanlimit").val(),                                //贷款额度
                    T_Actual: $("#T_Actual").val(),                                       //实际交易价
                    T_Located: $("#T_Located").val(),                                     //房屋坐落
                    T_PurposeID: $("#T_PurposeID option:checked").attr("value"),            //房屋用途编号
                    T_Activate: $("#T_Activate").val(),                                   //建成年代
                    T_ReportID: $("#T_ReportID option:checked").attr("value"),              //报告类型编号
                    T_Assess: T_Assess.toString(),                                                 //评估受理
                    T_DepartmentID: $("#T_DepartmentID option:checked").attr("value"),         //抵押物管理点（现场勘查所属部门id）
                    T_SiteSurveyid: $("#T_SiteSurveyid option:checked").attr("value"),         //抵押物管理点（现场勘查所属部门下的某员工）
                    T_Iid: LoginUserID,                                            //登记员(房产登记者),员工表中的外键
                }
            }
            //借款人
            var Collateral_BorrowerList = [];
            $(".addBorrower").each(function () {
                Collateral_BorrowerList.push({
                    T_Name: $(this).find(".T_Name").val(),
                    T_Idcard: $(this).find(".T_Idcard").val(),
                    T_Phone: $(this).find(".T_PhoneAll").val()
                });
            })
            var parms = {
                Collateral_Personal: Collateral_Personal,
                Collateral_BorrowerList: Collateral_BorrowerList
            }
            //房屋信息的录入添加
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Personal/PersonalOrBorrower",
                data: parms,
                success: function (data, status) {
                    if (data == true) {
                        layer.msg('登记成功!', { icon: 1, time: 2000 });
                        window.parent.location.reload();//刷新主窗体
                        // location.href = "pledge_equitiesShow.html";
                    } else {
                        layer.msg('登记失败!', { icon: 2, time: 1000 });
                    }

                }
            })

        }
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
    <script>
        $(function () {
            var b = 0;
            if (T_ReportNumber != "") {
                $.ajax({
                    type: "post",
                    data: { "": T_ReportNumber },
                    url: ApiUrl + "api/Personal/ShowCollateral_PersonalService",
                    // async: false,
                    success: function (data) {
                        if (data != null && data != "") {
                            if (data[0].T_Assess != "" && data[0].T_Assess != null) {
                                $(data[0].T_Assess.split(",")).each(function (i, dom) {
                                    $(":checkbox[value='" + dom + "'][name='T_Assess']").prop("checked", true);
                                });
                            }
                            $("#T_Loanlimit").val(data[0].T_Loanlimit);
                            $("#T_Actual").val(data[0].T_Actual);
                            $("#T_Located").val(data[0].T_Located);
                            $("#T_PurposeID").val(data[0].T_PurposeID);
                            $("#T_Activate").val(data[0].T_Activate);
                            $("#T_ReportID").val(data[0].T_ReportID);
                            $("#T_Linkman").val(data[0].T_Linkman);
                            $("#T_Phone").val(data[0].T_Phone);
                            $("#T_Loanyear").val(data[0].T_Loanyear);

                            $("#T_DepartmentID").val(data[0].T_DepartmentID);
                            $("#T_SiteSurveyid").val(data[0].T_SiteSurveyid);
                            $(data[1]).each(function (i, item) {
                                var html = '<div class="addBorrower" id=borrower' + b + '>'
                                        + '<div class="row cl">'
                                        + '    <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>借款人员姓名：</label>'
                                        + '    <div class="formControls col-xs-3 col-sm-3">'
                                        + '        <input type="text" class="input-text T_Name"  placeholder="请输入借款人员姓名" maxlength="10" id="T_Name' + b + '" name="T_Name' + b + '" value="' + item.T_Name + '' + b + '" required="required"/>'
                                        + '    </div>'
                                        + '    <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>身份证号：</label>'
                                        + '    <div class="formControls col-xs-3 col-sm-4">'
                                        + '        <input type="text" class="input-text T_Idcard"  placeholder="请输入身份证号" maxlength="18" id="T_Idcard' + b + '"  name="T_Idcard' + b + '" value="' + item.T_Idcard + '' + b + '" required="required"/>'
                                        + '    </div>'
                                        + '</div>'
                                        + '<div class="row cl">'
                                        + '    <label class="form-label col-xs-3 col-sm-2"><span class="c-red"></span>联系电话：</label>'
                                        + '    <div class="formControls col-xs-3 col-sm-3">'
                                        + '        <input type="text" class="input-text T_PhoneAll"  placeholder="请输入联系电话" maxlength="11" id="T_PhoneAll' + b + '"  name="T_PhoneAll' + b + '" value="' + item.T_Phone + '' + b + '" required="required"/>'
                                        + '    </div>'
                                        + '    <div class="formControls col-xs-6 col-sm-6">'
                                        + '        <input class="btn btn-danger radius" onclick="removeborrower(' + b + ')" value="删除借款人" type="button"/>'
                                        + '    </div>'
                                        + '</div></div>';
                                if (b >= 1) {
                                    $("#add").append(html);
                                }
                                else {
                                    $("#T_Name0").val(item.T_Name);
                                    $("#T_Idcard0").val(item.T_Idcard);
                                    $("#T_Phone0").val(item.T_Phone);
                                }
                                b++;

                            })
                        }
                    }
                })
            }
        })
    </script>
</body>
</html>
